package com.wiscamp.ninechapters;

import com.wiscamp.ninechapters.common.core.DateTimeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author yifeng 定时计划任务 此定时任务不支持分布式部署
 */
@Component
public class ScheduleExecutor {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /*@Autowired
    private StatisticsService statisticsService;

    @Autowired
    private AssignmentTaskService assignmentTaskService;*/

    /*@Autowired
    private WechatService wechatService;*/

  /*  @Autowired
    private MessageService messageService;*/

    //@Autowired
    /*public ScheduleExecutor(StatisticsService statisticsService, AssignmentTaskService assignmentTaskService) {
        this.statisticsService = statisticsService;
        this.assignmentTaskService = assignmentTaskService;
    }*/

    /**
     * 每天凌晨1点执行，计算知识点统计数据
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void calculatePointInfo() {
        logger.debug("The task is running: calculate point statistics info.");
        //statisticsService.calculatePointInfo();
    }

    /**
     * 每天凌晨2点执行，计算题统计信息
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void calculateItemInfo() {
        logger.debug("The task is running: calculate item statistics info.");
        var startDate = DateTimeHelper.getYesterdayDateString();
        var endDate = DateTimeHelper.getTodayDateString();
        //statisticsService.calculateItemInfo(startDate, endDate);
    }

    /**
     * 每天凌晨3点执行，计算学员统计信息
     */
    @Scheduled(cron = "0 0 3 * * ?")
    public void calculateMenteeInfo() {
        logger.debug("The task is running: calculate mentee statistics info.");
        var startDate = DateTimeHelper.getYesterdayDateString();
        //statisticsService.calculateMenteeInfo(startDate);
    }

    /**
     * 每天凌晨4点执行，放弃7天前没有完成的任务
     */
    @Scheduled(cron = "0 0 4 * * ?")
    public void abandonUncompletedTasks() {
        logger.debug("The task is running: abandon uncompleted tasks.");
        //assignmentTaskService.abandonUncompletedTasks();
    }

    /**
     * process application messages
     */
    @Scheduled(cron = "0 0/3 * * * ?")
    public void processPhoneMessages() {
        // logger.debug("The task is running: process messages.");
        //wechatService.processPhoneMessage();
        //messageService.processActivityMessage();
    }
}
